﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-Add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增租户</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-Edit" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>编辑租户</a></li>
                <li><a id="NF-Details" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看租户</a></li>
                <li><a id="NF-Delete" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除租户</a></li>
                <li class="split"></li>
                <li><a id="NF-Enabled" onclick="btn_enabled()"><i class="fa fa-play-circle"></i>启用</a></li>
                <li><a id="NF-Disabled" onclick="btn_disabled()"><i class="fa fa-stop-circle"></i>禁用</a></li>
                <li class="split"></li>
                <li><a onclick="btn_resperms()"><i class="fa fa-stop-circle"></i>资源权限</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="租户账号/租户名称" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/SystemManage/Tenant/GetGridJson",
            height: $(window).height() - 128,
            //rowNum: 20,
            colModel: [
                { label: '主键', name: 'Id', hidden: true },
                { label: '租户账号', name: 'TenantName', width: 80, align: 'left' },
                { label: '租户名称', name: 'FullName', width: 80, align: 'left' },
                { label: '创建时间', name: 'CreatedTime', width: 80, align: 'center' },
                {
                    label: "允许登录", name: "EnabledMark", width: 60, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return '<span class=\"label label-success\">正常</span>';
                        } else if (cellvalue == 0) {
                            return '<span class=\"label label-default\">禁用</span>';
                        }
                    }
                },
                { label: '备注', name: 'Description', width: 200, align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'CreatorTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增用户",
            url: "/SystemManage/Tenant/Form",
            width: "700px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Form",
            title: "修改用户",
            url: "/SystemManage/Tenant/Form?keyValue=" + keyValue,
            width: "700px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/SystemManage/Tenant/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().Id },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Details",
            title: "查看租户",
            url: "/SystemManage/Tenant/Details?keyValue=" + keyValue,
            width: "700px",
            height: "350px",
            btn: null,
        });
    }
    function btn_enabled() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalConfirm("注：您确定要【启用】该项租户吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/SystemManage/Tenant/EnabledForm",
                    param: { keyValue: keyValue },
                    success: function () {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                })
            }
        });
    }
    function btn_disabled() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalConfirm("注：您确定要【禁用】该项租户吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/SystemManage/Tenant/DisabledForm",
                    param: { keyValue: keyValue },
                    success: function () {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                })
            }
        });
    }
    function btn_resperms() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Details",
            title: "查看租户",
            url: "/SystemManage/Tenant/ResPerms?keyValue=" + keyValue,
            width: "570px",
            height: "550px",
            btn: null,
        });
    }
</script>